pub mod c_lib;
pub mod pointer;

/// 内存块
pub struct MemBlock {
    mem_size: usize,
    start_address: usize,
}

impl MemBlock {
    pub fn init_mem(size: usize) -> MemResult<Self> {
        let address = c_lib::create_mem_space(size)?;
        Ok(Self { mem_size: size, start_address: address })
    }

    pub fn start_boundary(&self) -> usize {
        self.start_address
    }

    pub fn end_boundary(&self) -> usize {
        self.start_address + self.mem_size
    }
}

impl Drop for MemBlock {
    fn drop(&mut self) {
        c_lib::delete_mem_space(self.start_address);
    }
}

type MemResult<T> = Result<T, MemErrors>;

/// 内存错误
pub enum MemErrors {
    MemoryCreateFailure,
    MemorySizeMismatching,
    MemoryCannotAlignment,
}